{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5ac91469",
   "metadata": {},
   "source": [
    "# 1. requests测试和学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "da853e14",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "82f5ca2f",
   "metadata": {},
   "outputs": [],
   "source": [
    "response = requests.get(\"http://127.0.0.1:8888/?token=fab5389d6f7dc3f32a018f8afc0ac6553e6a15da9b1695e6\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c1e9a227",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00f7f7f6",
   "metadata": {},
   "source": [
    "# 1.二进制的响应内容\n",
    "\n",
    "* bytes\n",
    "* content 可以识别任何格式的网页数据，但是不利于分析（流媒体：如图片，视频，音频）\n",
    "* json() 数据交换的常用表达式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0b3b2551",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'<!DOCTYPE HTML>\\n<html>\\n\\n<head>\\n    <meta charset=\"utf-8\">\\n\\n    <title>Home Page - Select or create a notebook</title>\\n    <link id=\"favicon\" rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/static/base/images/favicon.ico?v=50afa725b5de8b00030139d09b38620224d4e7dba47c07ef0e86d4643f30c9bfe6bb7e1a4a1c561aa32834480909a4b6fe7cd1e17f7159330b6b5914bf45a880\">\\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\\n    <link rel=\"stylesheet\" href=\"/static/components/jquery-ui/themes/smoothness/jquery-ui.min.css?v=fb45616eef2c454960f91fcd2a04efeda84cfacccf0c5d741ba2793dc1dbd6d3ab01aaae6485222945774c7d7a9a2e9fb87e0d8ef1ea96893aa6906147a371bb\" type=\"text/css\" />\\n    <link rel=\"stylesheet\" href=\"/static/components/jquery-typeahead/dist/jquery.typeahead.min.css?v=5edf53bf6bb9c3b1ddafd8594825a7e2ed621f19423e569c985162742f63911c09eba2c529f8fb47aebf27fafdfe287d563347f58c1126b278189a18871b6a9a\" type=\"text/css\" />\\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\\n    \\n    \\n    <link rel=\"stylesheet\" href=\"/static/style/style.min.css?v=56dfd556850eb17b7998c6828467598a322b41593edc758739c66cb2c3fea98f23d0dd8bf8b9b0f5d67bb976a50e4c34f789fe640cbb440fa089e1bf5ec170bd\" type=\"text/css\"/>\\n    \\n    <link rel=\"stylesheet\" href=\"/custom/custom.css\" type=\"text/css\" />\\n    <script src=\"/static/components/es6-promise/promise.min.js?v=bea335d74136a63ae1b5130f5ac9a50c6256a5f435e6e09fef599491a84d834a8b0f011ca3eaaca3b4ab6a2da2d3e1191567a2f171e60da1d10e5b9d52f84184\" type=\"text/javascript\" charset=\"utf-8\"></script>\\n    <script src=\"/static/components/react/react.production.min.js?v=9a0aaf84a316c8bedd6c2ff7d5b5e0a13f8f84ec02442346cba0b842c6c81a6bf6176e64f3675c2ebf357cb5bb048e0b527bd39377c95681d22468da3d5de735\" type=\"text/javascript\"></script>\\n    <script src=\"/static/components/react/react-dom.production.min.js?v=6fc58c1c4736868ff84f57bd8b85f2bdb985993a9392718f3b4af4bfa10fb4efba2b4ddd68644bd2a8daf0619a3844944c9c43f8528364a1aa6fc01ec1b8ae84\" type=\"text/javascript\"></script>\\n    <script src=\"/static/components/create-react-class/index.js?v=894ad57246e682b4cfbe7cd5e408dcd6b38d06af4de4f3425991e2676fdc2ef1732cbd19903104198878ae77de12a1996de3e7da3a467fb226bdda8f4618faec\" type=\"text/javascript\"></script>\\n    <script src=\"/static/components/requirejs/require.js?v=d37b48bb2137faa0ab98157e240c084dd5b1b5e74911723aa1d1f04c928c2a03dedf922d049e4815f7e5a369faa2e6b6a1000aae958b7953b5cc60411154f593\" type=\"text/javascript\" charset=\"utf-8\"></script>\\n    <script>\\n      require.config({\\n          \\n          urlArgs: \"v=20220307200913\",\\n          \\n          baseUrl: \\'/static/\\',\\n          paths: {\\n            \\'auth/js/main\\': \\'auth/js/main.min\\',\\n            custom : \\'/custom\\',\\n            nbextensions : \\'/nbextensions\\',\\n            kernelspecs : \\'/kernelspecs\\',\\n            underscore : \\'components/underscore/underscore-min\\',\\n            backbone : \\'components/backbone/backbone-min\\',\\n            jed: \\'components/jed/jed\\',\\n            jquery: \\'components/jquery/jquery.min\\',\\n            json: \\'components/requirejs-plugins/src/json\\',\\n            text: \\'components/requirejs-text/text\\',\\n            bootstrap: \\'components/bootstrap/dist/js/bootstrap.min\\',\\n            bootstraptour: \\'components/bootstrap-tour/build/js/bootstrap-tour.min\\',\\n            \\'jquery-ui\\': \\'components/jquery-ui/jquery-ui.min\\',\\n            moment: \\'components/moment/min/moment-with-locales\\',\\n            codemirror: \\'components/codemirror\\',\\n            termjs: \\'components/xterm.js/xterm\\',\\n            typeahead: \\'components/jquery-typeahead/dist/jquery.typeahead.min\\',\\n          },\\n          map: { // for backward compatibility\\n              \"*\": {\\n                  \"jqueryui\": \"jquery-ui\",\\n              }\\n          },\\n          shim: {\\n            typeahead: {\\n              deps: [\"jquery\"],\\n              exports: \"typeahead\"\\n            },\\n            underscore: {\\n              exports: \\'_\\'\\n            },\\n            backbone: {\\n              deps: [\"underscore\", \"jquery\"],\\n              exports: \"Backbone\"\\n            },\\n            bootstrap: {\\n              deps: [\"jquery\"],\\n              exports: \"bootstrap\"\\n            },\\n            bootstraptour: {\\n              deps: [\"bootstrap\"],\\n              exports: \"Tour\"\\n            },\\n            \"jquery-ui\": {\\n              deps: [\"jquery\"],\\n              exports: \"$\"\\n            }\\n          },\\n          waitSeconds: 30,\\n      });\\n\\n      require.config({\\n          map: {\\n              \\'*\\':{\\n                \\'contents\\': \\'services/contents\\',\\n              }\\n          }\\n      });\\n\\n      // error-catching custom.js shim.\\n      define(\"custom\", function (require, exports, module) {\\n          try {\\n              var custom = require(\\'custom/custom\\');\\n              console.debug(\\'loaded custom.js\\');\\n              return custom;\\n          } catch (e) {\\n              console.error(\"error loading custom.js\", e);\\n              return {};\\n          }\\n      })\\n\\n    document.nbjs_translations = {\"domain\": \"nbjs\", \"locale_data\": {\"nbjs\": {\"\": {\"domain\": \"nbjs\"}}}};\\n    document.documentElement.lang = navigator.language.toLowerCase();\\n    </script>\\n\\n    \\n    \\n\\n</head>\\n\\n<body class=\"\"\\n \\n\\n  \\n    data-jupyter-api-token=\"fab5389d6f7dc3f32a018f8afc0ac6553e6a15da9b1695e6\"\\n  \\n \\ndata-base-url=\"/\"\\ndata-notebook-path=\"\"\\ndata-terminals-available=\"True\"\\ndata-server-root=\"D:\\\\\"\\n\\ndir=\"ltr\">\\n\\n<noscript>\\n    <div id=\\'noscript\\'>\\n      Jupyter Notebook requires JavaScript.<br>\\n      Please enable it to proceed. \\n  </div>\\n</noscript>\\n\\n<div id=\"header\" role=\"navigation\" aria-label=\"Top Menu\">\\n  <div id=\"header-container\" class=\"container\">\\n  <div id=\"ipython_notebook\" class=\"nav navbar-brand\"><a href=\"/tree?token=fab5389d6f7dc3f32a018f8afc0ac6553e6a15da9b1695e6\" title=\\'dashboard\\'>\\n      <img src=\\'/static/base/images/logo.png?v=a2a176ee3cee251ffddf5fa21fe8e43727a9e5f87a06f9c91ad7b776d9e9d3d5e0159c16cc188a3965e00375fb4bc336c16067c688f5040c0c2d4bfdb852a9e4\\' alt=\\'Jupyter Notebook\\'/>\\n  </a></div>\\n\\n  \\n  <span class=\"flex-spacer\"></span>\\n  \\n  \\n  \\n    <span id=\"shutdown_widget\">\\n      <button id=\"shutdown\" class=\"btn btn-sm navbar-btn\"\\n              title=\"Stop the Jupyter server\">\\n          Quit\\n      </button>\\n    </span>\\n  \\n\\n  \\n  \\n  \\n  \\n\\n    <span id=\"login_widget\">\\n      \\n        <button id=\"logout\" class=\"btn btn-sm navbar-btn\">Logout</button>\\n      \\n    </span>\\n\\n  \\n\\n  \\n  \\n  </div>\\n  <div class=\"header-bar\"></div>\\n\\n  \\n  \\n</div>\\n\\n<div id=\"site\">\\n\\n\\n  <div id=\"ipython-main-app\" class=\"container\">\\n    <div id=\"tab_content\" class=\"tabbable\" role=\"main\">\\n      <ul id=\"tabs\" class=\"nav nav-tabs\">\\n        <li class=\"active\"><a href=\"#notebooks\" data-toggle=\"tab\">Files</a></li>\\n        <li><a href=\"#running\" data-toggle=\"tab\">Running</a></li>\\n        <li><a href=\"#clusters\" data-toggle=\"tab\" class=\"clusters_tab_link\" >Clusters</a></li>\\n      </ul>\\n      <div class=\"tab-content\">\\n        <div id=\"notebooks\" class=\"tab-pane active\">\\n          <div id=\"notebook_toolbar\" class=\"row\">\\n            <div class=\"col-sm-8 no-padding\">\\n              <div class=\"dynamic-instructions\">\\n                Select items to perform actions on them.\\n              </div>\\n              <div class=\"dynamic-buttons\">\\n                  <button  title=\"Duplicate selected\" aria-label=\"Duplicate selected\" class=\"duplicate-button btn btn-default btn-xs\" aria-describedby=\"tooltip1\">Duplicate </button>\\n                  <div role=\"tooltip\" id=\"tooltip1\" >Duplicate selected</div>\\n                  <button title=\"Rename selected\" aria-label=\"Rename selected\" class=\"rename-button btn btn-default btn-xs\" aria-describedby=\"tooltip2\">Rename</button>\\n                  <div role=\"tooltip\" id=\"tooltip2\" >Rename selected</div> \\n                  <button title=\"Move selected\" aria-label=\"Move selected\" class=\"move-button btn btn-default btn-xs\" aria-describedby=\"tooltip3\">Move</button>\\n                  <div role=\"tooltip\" id=\"tooltip3\" >Move selected</div> \\n                  <button title=\"Download selected\" aria-label=\"Download selected\" class=\"download-button btn btn-default btn-xs\" aria-describedby=\"tooltip4\">Download</button>\\n                  <div role=\"tooltip\" id=\"tooltip4\" >Download selected</div>\\n                  <button title=\"Shutdown selected notebook(s)\" aria-label=\"Shutdown selected notebook(s)\" class=\"shutdown-button btn btn-default btn-xs btn-warning\" aria-describedby=\"tooltip5\">Shutdown</button>\\n                  <div role=\"tooltip\" id=\"tooltip5\" >Shutdown selected notebook(s)</div>  \\n                  <button title=\"View selected\" aria-label=\"View selected\" class=\"view-button btn btn-default btn-xs\" aria-describedby=\"tooltip6\">View</button>\\n                  <div role=\"tooltip\" id=\"tooltip6\" >View selected</div> \\n                  <button title=\"Edit selected\" aria-label=\"Edit selected\" class=\"edit-button btn btn-default btn-xs\" aria-describedby=\"tooltip7\">Edit</button>\\n                  <div role=\"tooltip\" id=\"tooltip7\" >Edit selected</div>  \\n                  <button title=\"Delete selected\" aria-label=\"Delete selected\" class=\"delete-button btn btn-default btn-xs btn-danger\" aria-describedby=\"tooltip8\">\\n                    <i class=\"fa fa-trash\"></i>\\n                  </button>\\n                  <div role=\"tooltip\" id=\"tooltip8\" >Delete selected</div>\\n              </div>\\n            </div>\\n            <div class=\"col-sm-4 no-padding tree-buttons\">\\n              <div class=\"pull-right\">\\n                <form id=\\'alternate_upload\\'  class=\\'alternate_upload\\'>\\n                  <span id=\"notebook_list_info\">\\n                  <span id=\"upload_span\" class=\"btn btn-xs btn-default btn-upload\" role=\"button\" tabindex=\"0\">\\n                    <input id=\"upload_span_input\" title=\"Click to browse for a file to upload.\" type=\"file\" name=\"datafile\" class=\"fileinput\" multiple=\\'multiple\\' tabindex=\"-1\">\\n                    Upload\\n                  </span>\\n                  </span>\\n                </form>\\n                <div id=\"new-buttons\" class=\"btn-group\">\\n                  <button class=\"dropdown-toggle btn btn-default btn-xs\" id=\"new-dropdown-button\" data-toggle=\"dropdown\">\\n                  <span>New</span>\\n                  <span class=\"caret\"></span>\\n                  <span class=\"sr-only\">Toggle Dropdown</span>\\n                  </button>\\n                  <ul id=\"new-menu\" class=\"dropdown-menu\" role=\"menu\">\\n                    <li role=\"menuitem\" class=\"dropdown-header\" id=\"notebook-kernels\">Notebook:</li>\\n                    <li role=\"presentation\" class=\"divider\"></li>\\n                    <li role=\"menuitem\" class=\"dropdown-header\" >Other:</li>\\n                    <li role=\"none\" id=\"new-file\">\\n                        <a role=\"menuitem\" tabindex=\"-1\" href=\"#\">Text File</a>\\n                    </li>\\n                    <li role=\"none\" id=\"new-folder\">\\n                        <a role=\"menuitem\" tabindex=\"-1\" href=\"#\">Folder</a>\\n                    </li>\\n                    \\n                    <li role=\"none\" id=\"new-terminal\">\\n                        <a role=\"menuitem\" tabindex=\"-1\" href=\"#\">Terminal</a>\\n                    </li>\\n                    \\n                  </ul>\\n                </div>\\n                <div class=\"btn-group\">\\n                    <button id=\"refresh_notebook_list\" title=\"Refresh notebook list\"  aria-label=\"Refresh notebook list\" class=\"btn btn-default btn-xs\"><i class=\"fa fa-refresh\"></i></button>\\n                </div>\\n              </div>\\n            </div>\\n          </div>\\n          <div id=\"notebook_list\">\\n            <div id=\"notebook_list_header\" class=\"row list_header\">\\n              <div class=\"btn-group dropdown\" id=\"tree-selector\">\\n                <button title=\"Select All / None\" aria-label=\"Select All / None\" type=\"button\" class=\"btn btn-default btn-xs\" id=\"button-select-all\" role=\"checkbox\">\\n                  <input type=\"checkbox\" class=\"pull-left tree-selector\" id=\"select-all\" tabindex=\"-1\"><span id=\"counter-select-all\">&nbsp;</span></input>\\n                </button>\\n                <button title=\"Select Folders/All Notebooks/Running/Files\" class=\"btn btn-default btn-xs dropdown-toggle\" type=\"button\" id=\"tree-selector-btn\" data-toggle=\"dropdown\" aria-expanded=\"true\">\\n                  <span class=\"sr-only\">checkbox</span>\\n                  <span class=\"caret\"></span>\\n                  <span class=\"sr-only\">Toggle Dropdown</span>\\n                </button>\\n                <ul id=\\'selector-menu\\' class=\"dropdown-menu\" role=\"menu\" aria-labelledby=\"tree-selector-btn\">\\n                  <li role=\"none\"><a id=\"select-folders\" role=\"menuitem\" tabindex=\"-1\" href=\"#\" title=\"Select All Folders\"><i class=\"menu_icon folder_icon icon-fixed-width\"></i>&nbsp;Folders</a></li>\\n                  <li role=\"none\"><a id=\"select-notebooks\" role=\"menuitem\" tabindex=\"-1\" href=\"#\" title=\"Select All Notebooks\"><i class=\"menu_icon notebook_icon icon-fixed-width\"></i>&nbsp;All Notebooks</a></li>\\n                  <li role=\"none\"><a id=\"select-running-notebooks\" role=\"menuitem\" tabindex=\"-1\" href=\"#\" title=\"Select Running Notebooks\"><i class=\"menu_icon running_notebook_icon icon-fixed-width\"></i>&nbsp;Running</a></li>\\n                  <li role=\"none\"><a id=\"select-files\" role=\"menuitem\" tabindex=\"-1\" href=\"#\" title=\"Select All Files\"><i class=\"menu_icon file_icon icon-fixed-width\"></i>&nbsp;Files</a></li>\\n                </ul>\\n              </div>\\n              <div id=\"project_name\">\\n                <ul class=\"breadcrumb\">\\n                  <li><a href=\"/tree\"><i class=\"fa fa-folder\" alt=\"folder icon\"></i></a></li>\\n                \\n                </ul>\\n              </div>\\n              <div id=\"sort_buttons\" class=\"pull-right\">\\n                <div id=\"sort_name\" class=\"sort_button\">\\n                  <button type=\"button\" class=\"btn btn-xs btn-default sort-action\" id=\"sort-name\" aria-label=\"Sort by name\">\\n                        Name\\n                        <i class=\"fa fa-arrow-down\"></i>\\n                  </button>\\n                </div>\\n                <div id=\"last_modified\" class=\"sort_button\">\\n                    <button type=\"button\" class=\"btn btn-xs btn-default sort-action\" id=\"last-modified\" aria-label=\"Sort by last modified\">\\n                        Last Modified\\n                        <i class=\"fa\"></i>\\n                    </button>\\n                </div>\\n                <div id=\"file_size\" class=\"sort_button\">\\n                    <button type=\"button\" class=\"btn btn-xs btn-default sort-action\" id=\"file-size\" aria-label=\"Sort by file size\">\\n                        File size\\n                        <i class=\"fa\"></i>\\n                    </button>\\n                </div>\\n              </div>\\n            </div>\\n          </div>\\n        </div>\\n        <div id=\"running\" class=\"tab-pane\">\\n          <div id=\"running_toolbar\" class=\"row\">\\n            <div class=\"col-sm-8 no-padding\">\\n              <span id=\"running_list_info\">Currently running Jupyter processes</span>\\n            </div>\\n            <div class=\"col-sm-4 no-padding tree-buttons\">\\n              <span id=\"running_buttons\" class=\"pull-right\">\\n              <button id=\"refresh_running_list\" title=\"Refresh running list\" aria-label=\"Refresh running list\" class=\"btn btn-default btn-xs\"><i class=\"fa fa-refresh\"></i></button>\\n              </span>\\n            </div>\\n          </div>\\n          <div class=\"panel-group\" id=\"accordion\" >\\n            <div class=\"panel panel-default\">\\n              <div class=\"panel-heading\">\\n                <a data-toggle=\"collapse\" data-target=\"#collapseOne\" href=\"#\">\\n                  Terminals\\n                </a>\\n              </div>\\n              <div id=\"collapseOne\" class=\" collapse in\">\\n                <div class=\"panel-body\">\\n                  <div id=\"terminal_list\">\\n                    <div id=\"terminal_list_header\" class=\"row list_placeholder\">\\n                    \\n                      <div> There are no terminals running. </div>\\n                    \\n                    </div>\\n                  </div>\\n                </div>\\n              </div>\\n            </div>\\n            <div class=\"panel panel-default\">\\n              <div class=\"panel-heading\">\\n                <a data-toggle=\"collapse\" data-target=\"#collapseTwo\" href=\"#\">\\n                  Notebooks\\n                </a>\\n              </div>\\n              <div id=\"collapseTwo\" class=\" collapse in\">\\n                <div class=\"panel-body\">\\n                  <div id=\"running_list\">\\n                    <div id=\"running_list_placeholder\" class=\"row list_placeholder\">\\n                      <div> There are no notebooks running. </div>\\n                    </div>\\n                  </div>\\n                </div>\\n              </div>\\n            </div>\\n          </div>\\n        </div>\\n        <div id=\"clusters\" class=\"tab-pane\">\\n          Clusters tab is now provided by IPython parallel.\\n          See \\'<a href=\"https://github.com/ipython/ipyparallel\">IPython parallel</a>\\' for installation details.\\n        </div>\\n      </div><!-- class:tab-content -->\\n    </div><!-- id:tab_content -->\\n  </div><!-- ipython-main-app  -->\\n\\n\\n</div>\\n\\n\\n\\n\\n\\n    \\n\\n    <script type=\"text/javascript\">\\n      (\\'#element\\').tooltip(\\'enable\\')\\n    </script>\\n\\n<script src=\"/static/tree/js/main.min.js?v=e37855cd299f6edbfb33deaf95a41c5c5e2a2057426822be7e214be679b8c8e8f031ecf6ba0b1a4f0aa8864d58e470c6e433f8f245c81d9518f9fe472ec2d53a\" type=\"text/javascript\" charset=\"utf-8\"></script>\\n\\n\\n\\n<script type=\\'text/javascript\\'>\\n  function _remove_token_from_url() {\\n    if (window.location.search.length <= 1) {\\n      return;\\n    }\\n    var search_parameters = window.location.search.slice(1).split(\\'&\\');\\n    for (var i = 0; i < search_parameters.length; i++) {\\n      if (search_parameters[i].split(\\'=\\')[0] === \\'token\\') {\\n        // remote token from search parameters\\n        search_parameters.splice(i, 1);\\n        var new_search = \\'\\';\\n        if (search_parameters.length) {\\n          new_search = \\'?\\' + search_parameters.join(\\'&\\');\\n        }\\n        var new_url = window.location.origin + \\n                      window.location.pathname + \\n                      new_search + \\n                      window.location.hash;\\n        window.history.replaceState({}, \"\", new_url);\\n        return;\\n      }\\n    }\\n  }\\n  _remove_token_from_url();\\n</script>\\n</body>\\n\\n</html>'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.content"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26552021",
   "metadata": {},
   "source": [
    "## 2.Json 的相应内容\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "50d1144b",
   "metadata": {},
   "outputs": [],
   "source": [
    "r=requests.get('https://api.github.com/events')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ffbb2ccd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e9577c0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'id': '20615084985',\n",
       " 'type': 'PushEvent',\n",
       " 'actor': {'id': 89167146,\n",
       "  'login': 'liviafort',\n",
       "  'display_login': 'liviafort',\n",
       "  'gravatar_id': '',\n",
       "  'url': 'https://api.github.com/users/liviafort',\n",
       "  'avatar_url': 'https://avatars.githubusercontent.com/u/89167146?'},\n",
       " 'repo': {'id': 467080904,\n",
       "  'name': 'liviafort/dsmovie',\n",
       "  'url': 'https://api.github.com/repos/liviafort/dsmovie'},\n",
       " 'payload': {'push_id': 9284016233,\n",
       "  'size': 1,\n",
       "  'distinct_size': 1,\n",
       "  'ref': 'refs/heads/main',\n",
       "  'head': '2b014b3f763bb807ecbc0e648192021eede1fa8f',\n",
       "  'before': '0946a3e2968cae3e4038f8198afa854a65f3a7a9',\n",
       "  'commits': [{'sha': '2b014b3f763bb807ecbc0e648192021eede1fa8f',\n",
       "    'author': {'email': 'livia.fortunato@academico.ifpb.edu.br',\n",
       "     'name': 'Livia Fortunato'},\n",
       "    'message': 'Bootstrap',\n",
       "    'distinct': True,\n",
       "    'url': 'https://api.github.com/repos/liviafort/dsmovie/commits/2b014b3f763bb807ecbc0e648192021eede1fa8f'}]},\n",
       " 'public': True,\n",
       " 'created_at': '2022-03-07T12:27:21Z'}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49645ce2",
   "metadata": {},
   "source": [
    "## 3.payload\n",
    "\n",
    "* 作为请求输入的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f9c4a0cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = {\n",
    "    \"name\":\"kanekikeh\",\n",
    "    \"password\":\"123\"\n",
    "}\n",
    "r = requests.get(\"http://httpbin.org/get\",params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7a290c5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'http://httpbin.org/get?name=kanekikeh&password=123'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "a59c87f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "85ea0807",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\\n  \"args\": {\\n    \"name\": \"kanekikeh\", \\n    \"password\": \"123\"\\n  }, \\n  \"headers\": {\\n    \"Accept\": \"*/*\", \\n    \"Accept-Encoding\": \"gzip, deflate\", \\n    \"Host\": \"httpbin.org\", \\n    \"User-Agent\": \"python-requests/2.25.1\", \\n    \"X-Amzn-Trace-Id\": \"Root=1-6225fd45-0335f57208073b5c158dcce8\"\\n  }, \\n  \"origin\": \"112.96.230.207\", \\n  \"url\": \"http://httpbin.org/get?name=kanekikeh&password=123\"\\n}\\n'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "15e0729e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method Response.json of <Response [200]>>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d255e7f",
   "metadata": {},
   "source": [
    "# 2. 实践 face++"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "6635b4fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.导入需要的requests模块\n",
    "import requests\n",
    "\n",
    "# 2.准备API的接口身份\n",
    "API_KEY = \"5G6CNIUGghmy_JcyAxNV-bDSVWy0XeI4\"\n",
    "API_Secret =\"rdArZ6BfSA19vSCeC_ArYzk2jqXK00Mi\"\n",
    "\n",
    "# 3.准备base URL（face detect）\n",
    "base_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "# 4.请求方法：POST\n",
    "\n",
    "# 5.准备请求参数：payload\n",
    "payload = {\n",
    "    \"api_key\" : API_KEY,\n",
    "    \"api_secret\" : API_Secret,\n",
    "    \"image_url\" : \"https://ts1.cn.mm.bing.net/th?id=OIP-C.7azTJ7hlZYtLO3Tz-fs0RQHaHa&w=183&h=170&c=8&rs=1&qlt=90&o=6&dpr=1.65&pid=3.1&rm=2\",\n",
    "    \"return_landmark\" : 1,\n",
    "    \"return_attributes\" : \"gender,age,smiling\"\n",
    "    \n",
    "}\n",
    "\n",
    "# 6.请求数据\n",
    "r = requests.post(base_url,payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "f97e7e40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "340df45c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"request_id\":\"1646658028,b2d782a4-57b5-4768-b16c-268e555a4398\",\"time_used\":491,\"faces\":[{\"face_token\":\"a09fb8de5cdc42ceb700a2c93d52ce08\",\"face_rectangle\":{\"top\":102,\"left\":71,\"width\":161,\"height\":161},\"landmark\":{\"contour_chin\":{\"x\":148,\"y\":260},\"contour_left1\":{\"x\":71,\"y\":131},\"contour_left2\":{\"x\":71,\"y\":149},\"contour_left3\":{\"x\":74,\"y\":166},\"contour_left4\":{\"x\":78,\"y\":184},\"contour_left5\":{\"x\":83,\"y\":201},\"contour_left6\":{\"x\":90,\"y\":217},\"contour_left7\":{\"x\":100,\"y\":232},\"contour_left8\":{\"x\":113,\"y\":245},\"contour_left9\":{\"x\":128,\"y\":255},\"contour_right1\":{\"x\":232,\"y\":132},\"contour_right2\":{\"x\":231,\"y\":151},\"contour_right3\":{\"x\":228,\"y\":169},\"contour_right4\":{\"x\":224,\"y\":186},\"contour_right5\":{\"x\":219,\"y\":204},\"contour_right6\":{\"x\":211,\"y\":220},\"contour_right7\":{\"x\":200,\"y\":234},\"contour_right8\":{\"x\":186,\"y\":247},\"contour_right9\":{\"x\":169,\"y\":256},\"left_eye_bottom\":{\"x\":111,\"y\":136},\"left_eye_center\":{\"x\":113,\"y\":131},\"left_eye_left_corner\":{\"x\":97,\"y\":131},\"left_eye_lower_left_quarter\":{\"x\":103,\"y\":134},\"left_eye_lower_right_quarter\":{\"x\":121,\"y\":136},\"left_eye_pupil\":{\"x\":113,\"y\":130},\"left_eye_right_corner\":{\"x\":129,\"y\":135},\"left_eye_top\":{\"x\":113,\"y\":124},\"left_eye_upper_left_quarter\":{\"x\":104,\"y\":126},\"left_eye_upper_right_quarter\":{\"x\":122,\"y\":127},\"left_eyebrow_left_corner\":{\"x\":77,\"y\":118},\"left_eyebrow_lower_left_quarter\":{\"x\":91,\"y\":115},\"left_eyebrow_lower_middle\":{\"x\":104,\"y\":115},\"left_eyebrow_lower_right_quarter\":{\"x\":119,\"y\":118},\"left_eyebrow_right_corner\":{\"x\":134,\"y\":119},\"left_eyebrow_upper_left_quarter\":{\"x\":89,\"y\":108},\"left_eyebrow_upper_middle\":{\"x\":105,\"y\":106},\"left_eyebrow_upper_right_quarter\":{\"x\":120,\"y\":110},\"mouth_left_corner\":{\"x\":118,\"y\":204},\"mouth_lower_lip_bottom\":{\"x\":149,\"y\":220},\"mouth_lower_lip_left_contour1\":{\"x\":133,\"y\":208},\"mouth_lower_lip_left_contour2\":{\"x\":126,\"y\":212},\"mouth_lower_lip_left_contour3\":{\"x\":136,\"y\":218},\"mouth_lower_lip_right_contour1\":{\"x\":166,\"y\":206},\"mouth_lower_lip_right_contour2\":{\"x\":174,\"y\":210},\"mouth_lower_lip_right_contour3\":{\"x\":163,\"y\":217},\"mouth_lower_lip_top\":{\"x\":149,\"y\":209},\"mouth_right_corner\":{\"x\":184,\"y\":202},\"mouth_upper_lip_bottom\":{\"x\":149,\"y\":209},\"mouth_upper_lip_left_contour1\":{\"x\":141,\"y\":202},\"mouth_upper_lip_left_contour2\":{\"x\":130,\"y\":203},\"mouth_upper_lip_left_contour3\":{\"x\":134,\"y\":207},\"mouth_upper_lip_right_contour1\":{\"x\":156,\"y\":201},\"mouth_upper_lip_right_contour2\":{\"x\":169,\"y\":202},\"mouth_upper_lip_right_contour3\":{\"x\":166,\"y\":206},\"mouth_upper_lip_top\":{\"x\":148,\"y\":203},\"nose_contour_left1\":{\"x\":136,\"y\":134},\"nose_contour_left2\":{\"x\":130,\"y\":164},\"nose_contour_left3\":{\"x\":135,\"y\":184},\"nose_contour_lower_middle\":{\"x\":147,\"y\":187},\"nose_contour_right1\":{\"x\":160,\"y\":134},\"nose_contour_right2\":{\"x\":165,\"y\":164},\"nose_contour_right3\":{\"x\":159,\"y\":183},\"nose_left\":{\"x\":125,\"y\":177},\"nose_right\":{\"x\":170,\"y\":177},\"nose_tip\":{\"x\":146,\"y\":175},\"right_eye_bottom\":{\"x\":189,\"y\":137},\"right_eye_center\":{\"x\":189,\"y\":131},\"right_eye_left_corner\":{\"x\":171,\"y\":133},\"right_eye_lower_left_quarter\":{\"x\":180,\"y\":135},\"right_eye_lower_right_quarter\":{\"x\":198,\"y\":135},\"right_eye_pupil\":{\"x\":188,\"y\":129},\"right_eye_right_corner\":{\"x\":205,\"y\":131},\"right_eye_top\":{\"x\":189,\"y\":124},\"right_eye_upper_left_quarter\":{\"x\":179,\"y\":126},\"right_eye_upper_right_quarter\":{\"x\":198,\"y\":126},\"right_eyebrow_left_corner\":{\"x\":163,\"y\":119},\"right_eyebrow_lower_left_quarter\":{\"x\":178,\"y\":118},\"right_eyebrow_lower_middle\":{\"x\":194,\"y\":116},\"right_eyebrow_lower_right_quarter\":{\"x\":209,\"y\":117},\"right_eyebrow_right_corner\":{\"x\":224,\"y\":119},\"right_eyebrow_upper_left_quarter\":{\"x\":177,\"y\":111},\"right_eyebrow_upper_middle\":{\"x\":193,\"y\":108},\"right_eyebrow_upper_right_quarter\":{\"x\":210,\"y\":110}},\"attributes\":{\"gender\":{\"value\":\"Female\"},\"age\":{\"value\":25},\"smile\":{\"value\":99.379,\"threshold\":50.000}}}],\"image_id\":\"wfutoHwxPxMM8YdpGEcw6A==\",\"face_num\":1}\\n'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "c8f32246",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1646658028,b2d782a4-57b5-4768-b16c-268e555a4398',\n",
       " 'time_used': 491,\n",
       " 'faces': [{'face_token': 'a09fb8de5cdc42ceb700a2c93d52ce08',\n",
       "   'face_rectangle': {'top': 102, 'left': 71, 'width': 161, 'height': 161},\n",
       "   'landmark': {'contour_chin': {'x': 148, 'y': 260},\n",
       "    'contour_left1': {'x': 71, 'y': 131},\n",
       "    'contour_left2': {'x': 71, 'y': 149},\n",
       "    'contour_left3': {'x': 74, 'y': 166},\n",
       "    'contour_left4': {'x': 78, 'y': 184},\n",
       "    'contour_left5': {'x': 83, 'y': 201},\n",
       "    'contour_left6': {'x': 90, 'y': 217},\n",
       "    'contour_left7': {'x': 100, 'y': 232},\n",
       "    'contour_left8': {'x': 113, 'y': 245},\n",
       "    'contour_left9': {'x': 128, 'y': 255},\n",
       "    'contour_right1': {'x': 232, 'y': 132},\n",
       "    'contour_right2': {'x': 231, 'y': 151},\n",
       "    'contour_right3': {'x': 228, 'y': 169},\n",
       "    'contour_right4': {'x': 224, 'y': 186},\n",
       "    'contour_right5': {'x': 219, 'y': 204},\n",
       "    'contour_right6': {'x': 211, 'y': 220},\n",
       "    'contour_right7': {'x': 200, 'y': 234},\n",
       "    'contour_right8': {'x': 186, 'y': 247},\n",
       "    'contour_right9': {'x': 169, 'y': 256},\n",
       "    'left_eye_bottom': {'x': 111, 'y': 136},\n",
       "    'left_eye_center': {'x': 113, 'y': 131},\n",
       "    'left_eye_left_corner': {'x': 97, 'y': 131},\n",
       "    'left_eye_lower_left_quarter': {'x': 103, 'y': 134},\n",
       "    'left_eye_lower_right_quarter': {'x': 121, 'y': 136},\n",
       "    'left_eye_pupil': {'x': 113, 'y': 130},\n",
       "    'left_eye_right_corner': {'x': 129, 'y': 135},\n",
       "    'left_eye_top': {'x': 113, 'y': 124},\n",
       "    'left_eye_upper_left_quarter': {'x': 104, 'y': 126},\n",
       "    'left_eye_upper_right_quarter': {'x': 122, 'y': 127},\n",
       "    'left_eyebrow_left_corner': {'x': 77, 'y': 118},\n",
       "    'left_eyebrow_lower_left_quarter': {'x': 91, 'y': 115},\n",
       "    'left_eyebrow_lower_middle': {'x': 104, 'y': 115},\n",
       "    'left_eyebrow_lower_right_quarter': {'x': 119, 'y': 118},\n",
       "    'left_eyebrow_right_corner': {'x': 134, 'y': 119},\n",
       "    'left_eyebrow_upper_left_quarter': {'x': 89, 'y': 108},\n",
       "    'left_eyebrow_upper_middle': {'x': 105, 'y': 106},\n",
       "    'left_eyebrow_upper_right_quarter': {'x': 120, 'y': 110},\n",
       "    'mouth_left_corner': {'x': 118, 'y': 204},\n",
       "    'mouth_lower_lip_bottom': {'x': 149, 'y': 220},\n",
       "    'mouth_lower_lip_left_contour1': {'x': 133, 'y': 208},\n",
       "    'mouth_lower_lip_left_contour2': {'x': 126, 'y': 212},\n",
       "    'mouth_lower_lip_left_contour3': {'x': 136, 'y': 218},\n",
       "    'mouth_lower_lip_right_contour1': {'x': 166, 'y': 206},\n",
       "    'mouth_lower_lip_right_contour2': {'x': 174, 'y': 210},\n",
       "    'mouth_lower_lip_right_contour3': {'x': 163, 'y': 217},\n",
       "    'mouth_lower_lip_top': {'x': 149, 'y': 209},\n",
       "    'mouth_right_corner': {'x': 184, 'y': 202},\n",
       "    'mouth_upper_lip_bottom': {'x': 149, 'y': 209},\n",
       "    'mouth_upper_lip_left_contour1': {'x': 141, 'y': 202},\n",
       "    'mouth_upper_lip_left_contour2': {'x': 130, 'y': 203},\n",
       "    'mouth_upper_lip_left_contour3': {'x': 134, 'y': 207},\n",
       "    'mouth_upper_lip_right_contour1': {'x': 156, 'y': 201},\n",
       "    'mouth_upper_lip_right_contour2': {'x': 169, 'y': 202},\n",
       "    'mouth_upper_lip_right_contour3': {'x': 166, 'y': 206},\n",
       "    'mouth_upper_lip_top': {'x': 148, 'y': 203},\n",
       "    'nose_contour_left1': {'x': 136, 'y': 134},\n",
       "    'nose_contour_left2': {'x': 130, 'y': 164},\n",
       "    'nose_contour_left3': {'x': 135, 'y': 184},\n",
       "    'nose_contour_lower_middle': {'x': 147, 'y': 187},\n",
       "    'nose_contour_right1': {'x': 160, 'y': 134},\n",
       "    'nose_contour_right2': {'x': 165, 'y': 164},\n",
       "    'nose_contour_right3': {'x': 159, 'y': 183},\n",
       "    'nose_left': {'x': 125, 'y': 177},\n",
       "    'nose_right': {'x': 170, 'y': 177},\n",
       "    'nose_tip': {'x': 146, 'y': 175},\n",
       "    'right_eye_bottom': {'x': 189, 'y': 137},\n",
       "    'right_eye_center': {'x': 189, 'y': 131},\n",
       "    'right_eye_left_corner': {'x': 171, 'y': 133},\n",
       "    'right_eye_lower_left_quarter': {'x': 180, 'y': 135},\n",
       "    'right_eye_lower_right_quarter': {'x': 198, 'y': 135},\n",
       "    'right_eye_pupil': {'x': 188, 'y': 129},\n",
       "    'right_eye_right_corner': {'x': 205, 'y': 131},\n",
       "    'right_eye_top': {'x': 189, 'y': 124},\n",
       "    'right_eye_upper_left_quarter': {'x': 179, 'y': 126},\n",
       "    'right_eye_upper_right_quarter': {'x': 198, 'y': 126},\n",
       "    'right_eyebrow_left_corner': {'x': 163, 'y': 119},\n",
       "    'right_eyebrow_lower_left_quarter': {'x': 178, 'y': 118},\n",
       "    'right_eyebrow_lower_middle': {'x': 194, 'y': 116},\n",
       "    'right_eyebrow_lower_right_quarter': {'x': 209, 'y': 117},\n",
       "    'right_eyebrow_right_corner': {'x': 224, 'y': 119},\n",
       "    'right_eyebrow_upper_left_quarter': {'x': 177, 'y': 111},\n",
       "    'right_eyebrow_upper_middle': {'x': 193, 'y': 108},\n",
       "    'right_eyebrow_upper_right_quarter': {'x': 210, 'y': 110}},\n",
       "   'attributes': {'gender': {'value': 'Female'},\n",
       "    'age': {'value': 25},\n",
       "    'smile': {'value': 99.379, 'threshold': 50.0}}}],\n",
       " 'image_id': 'wfutoHwxPxMM8YdpGEcw6A==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
